﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using DataService;
using DTO;

public partial class Account_editContact : BasePage
{
    private Contact _contact;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!string.IsNullOrEmpty(Request.QueryString["c"]))
        {
            using (ContactService service = new ContactService())
            {
                int id = int.Parse(Request.QueryString["c"]);
                _contact = service.GetContact(id);
            }
        }

        if (!IsPostBack)
        {

            Initial();
        }
    }

    public void Initial()
    {
        if (_contact != null)
        {
            ContactSubmit1.Contact = _contact;
        }
    }
        
    protected void btAddUser_Click(object sender, EventArgs e)
    {
        using (ContactService service = new ContactService())
        {
            service.SaveContact(UserLogin.Customer.Id, UserLogin.Id, ContactSubmit1.Contact);

            using (ContactService contactService = new ContactService())
            {
                UserLogin.Customer.Contacts = contactService.GetContacts(UserLogin.Customer.Id);
            }

            Response.Redirect("Default.aspx");
        }
    }
}